<?
ob_start(); 
include("common/header.html");
include("common/left.html");
$out_html=ob_get_contents();
ob_end_clean();

$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:10;
$op=$_REQUEST['op']?$_REQUEST["op"]:date("Y-m-d",strtotime("-1 month"));
$ed=$_REQUEST['ed']?$_REQUEST["ed"]:date("Y-m-d");
$oper=$opid=$list=$ids=array();
// 取得下属成员
$sel="select son_id,dname from pft_member_relationship r left join pft_member m on son_id=m.id where parent_id=".$_SESSION['sid']." and son_id_type=0 and r.status=0 and m.status=0 order by r.rectime desc";
$GLOBALS['le']->query($sel);
while($row=$GLOBALS['le']->fetch_assoc()){
	$ids[$row['son_id']]=$row['dname'];
}
exit;
$aids=array_keys($ids);// 下属成员ID
// if($aids){
	// $lmoney = array();
	// $retXml = $s->PFT_Member_Fund(implode(",",$aids), 0);
	// $object = simplexml_load_string($retXml);
	// foreach($object->Rec as $ct){
		// $fid = (string)$ct->UUfid;
		// $money = (string)$ct->UUamoney;
		// $lmoney[$fid] = $money;
		// $all+=$money;
	// }
// }
if($aids){
	$sel="select fid,group_concat(lmoney order by rectime DESC) lm from pft_member_journal where fid in (".implode(",",$aids).") and dtype=3 and ptype=0 and rectime between '".$op." 00:00:00' and '".$ed." 23:59:59' group by fid";//echo $sel;
	// echo $sel;
	// exit;
	$GLOBALS['le']->query($sel);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$lm=explode(",",$row['lm']);
		$lmoney[$row['fid']]=$lm[0];
		$all+=$lm[0];
	}
	$_ids=array_diff($aids,array_keys($lmoney));
	if($_ids){
		$sel="select fid,group_concat(lmoney order by rectime ASC) lm from pft_member_journal where fid in (".implode(",",$_ids).") and dtype=3 and ptype=0 and rectime>'".$ed." 23:59:59' group by fid";//echo $sel;
		$GLOBALS['le']->query($sel);
		while($row=$GLOBALS['le']->fetch_assoc()){
			$lm=explode(",",$row['lm']);
			$lmoney[$row['fid']]=$lm[0];
			$all+=$lm[0];
		}
	}
	$_ids=array_diff($aids,array_keys($lmoney));
	foreach($_ids as $v){
		$money=simplexml_load_string($s->PFT_Member_Fund($v,0));
		$lmoney[$v]=$money->Rec[0]->UUamoney;
		$all+=$money->Rec[0]->UUamoney;
	}
}
// 导出Excel
if(isset($_REQUEST['act']) && $_REQUEST['act']=='loadExcel'){
	$Excel = array();
	$filename = $_SESSION['dname'].'成员实时账户金额-'.date('YmdHis');
	$Excel[0]['a']='成员名称';
	$Excel[0]['b']='时时账户金额';
	$i=1;
	foreach($aids as $id){
		$n++;
		$Excel[$n]['a']=$ids[$id];
		$Excel[$n]['b']=$lmoney[$id]/100;
	}
	$xls = new SimpleExcel('UTF-8', true,'实时账户金额');
    $xls->addArray($Excel);
    $xls->generateXML($filename);
	exit;
}
echo $out_html;
?>
<link rel="stylesheet" type="text/css" href="css/page.css"/>
<link rel="stylesheet" type="text/css" href="http://www.16u.cc/d/css/JsPage.css" />
<script type="text/javascript" src="js/Calendar.js"></script>
<script type="text/javascript" src="http://www.16u.com/manage/finance/js/JsPage.js"></script>
<style>
.disredtab{ width:100%; text-align:center; margin:20px 0;}
.disredtab thead{ border:1px solid #DDEEFB; background:#F3FAFF;}
.disredtab th{ text-align:center; height:30px; line-height:30px;}
.disredtab td{ padding:8px 0; line-height:18px; border-bottom:1px solid #DDD; text-align:center;}
.disredtab td.txtlf{ text-align:left; padding-left:15px;}
.disredtab td.add{ color:#090;}
.disredtab td.redu{ color:#F00;}
.disredtab tfoot td.txtrig{ text-align:right;}
.disredtab tfoot td{ font-weight:bold;}
.disredtab td.lm{ color:#45637F; font-weight:bold;}
.search_zjl{margin-top:15px;color:#666;line-height:35px; padding-left:15px;}
.time{ height:18px; line-height:18px; padding:2px 4px;background: url("images/rili.png") no-repeat scroll right center white;border: 1px solid #7F9DB9; padding-right:20px; width:90px;}
.zjlbtn{width:81px;height:30px;border:0;background:url(../images/search.png) no-repeat;cursor:pointer; margin-left:30px;}
.zjlbtn:hover{ background-position:left bottom;}
</style>

<div class="r_content">
    <h3 class="mc_title">
        <span class=""><a href="rrecord.html" class="">分销商资金记录</a></span>
        <span class="mctit_1"><span class="mctit_2">成员资金查看</span></span>
    </h3>
    <div class="search_zjl">
    	<form>
        	<b>时间查询：</b>
        	<!-- <span><input type="text" class="time" name="op" id="begintime" onmouseup="SelectDate(this,'yyyy-MM-dd',0,0)" value="<?=$op?>" /> </span> 到  -->
            <span><input type="text" class="time" name="ed" id="endDate" onmouseup="SelectDate(this,'yyyy-MM-dd',0,0)" value="<?=$ed?>"/></span>
            <span><input type="submit" value="" class="zjlbtn" /></span>
        </form>
    </div>
    <table class="disredtab">
        <thead>
            <th>成员名称</th>
            <th>时时账户金额</th>
        </thead>
        <tbody>
        <?foreach($ids as $k=>$v){?>
            <tr>
                <td class="txtlf"><?=$v?></td>
                <td class="lm"><?=$lmoney[$k]/100?></td>
            </tr>
        <?}?>
    	</tbody>
        <tfoot>
        	<td class="txtrig">总金额：</td>
        	<td class="lm"><?=$all/100?></td>
        </tfoot>
    </table>
	<div class="" id="clear"></div>
<script type="text/javascript">
var addDivFunc=function(div){
	var settle=document.getElementById("clear");
	settle.parentNode.insertBefore(div,settle);
}
var trs=[];//document.getElementsByTagName("tr"),
var lists=[];
$("table tbody tr").each(function(i,e){
	trs.push(e);
});
for(var i=0,len=trs.length;i<len;i++){
	lists.push(trs[i]);
}
var Jspage=new JsPage(20,lists.length,lists,addDivFunc);
Jspage.showpage(0);
</script>
</div>
<?include("common/footer.html");?>